<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>
<body>
    <div id="app">
        <p>我是根元素</p>
        <p ref="rootPtag">我是根元素第二</p>
        <!-- 通过ref 可以让子组件挂载在refs下 可以直接访问方法和data数据并修改 -->
        <my-one ref="myOne"></my-one>
    </div>    
    <script>
        Vue.component("my-one",{
            data(){
                return {
                    message:"子组件的message"
                }
            },
            // 访问
            template:`
            <div style="border:1px solid red">
                <p>{{message}}</p>
                <p>我是组件</p>
            </div>
            `,
            methods: {
                print(){
                    console.log("子组件的print方法");
                }
            },
        });
        var app = new Vue({
            el:"#app",
            data:{
                msg:'父组件原始值'
            },
            created(){
                console.log(this.$refs.rootPtag);
            },
            mounted() {
                console.log(this.$refs.rootPtag);
                this.$refs.rootPtag.style.background="red"
            },
        })
    </script>
</body>
</html>